package exam.alibaba;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenhong
 * @version 1.0
 * @description TODO
 * @date 2023/4/28 15:44
 */
public class Main4 {
    public static void main(String[] args) {
        System.out.println(new Main4().fun("01010010010"));

    }
    int fun(String s) {
        List<Integer> list = new ArrayList<>();
        for (int i = 0; i < s.length(); i++) {
            if (s.charAt(i) == '0') {
                list.add(i);
            }
        }
        if (list.size() <= 1)
            return 0;
        int ans = 0;
        if (list.size() % 2 == 0) {
            for (int i = 0; i < list.size(); i += 2) {
                ans += list.get(i + 1) - list.get(i);
            }
            return ans;
        } else {
            ans = Integer.MAX_VALUE;
            for (int k = 0; k < list.size(); k += 2) {
                int count = 0;
                for (int i = 0; i < k; i += 2) {
                    count += list.get(i + 1) - list.get(i);
                }
                for (int i = k + 1; i < list.size(); i += 2) {
                    count += list.get(i + 1) - list.get(i);
                }
                ans = Math.min(ans,count);
            }
        }
        return ans;
    }
}
